package com.lq.educationsystem.lqclasses.service.impl;

import com.lq.educationsystem.common.util.*;
import com.lq.educationsystem.common.vo.ClassesSubjectPageVo;
import com.lq.educationsystem.lqclasses.mapper.ClassesSubjectTbMapper;
import com.lq.educationsystem.lqclasses.service.ClassesSubjectBaseService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lq.educationsystem.lqclasses.entiy.ClassesSubjectTb;

import java.util.List;

@Service
public class ClassesSubjectBaseImpl implements ClassesSubjectBaseService {
    @Autowired
    ClassesSubjectTbMapper classesSubjectTbMapper;
    @Override
    public void insertInfo(ClassesSubjectTb classesSubjectInfo) {
        int row = classesSubjectTbMapper.insert(classesSubjectInfo);
        System.out.println("ClassesSubject插入的数据： "+classesSubjectInfo);
        System.out.println("ClassesSubject插入数据影响的行数： "+row);
    }

    @Override
    public void deleteById(Integer classesSubjectId) {
        int row = classesSubjectTbMapper.deleteByPrimaryKey(Long.valueOf(classesSubjectId));

        System.out.println("ClassesSubject删除数据影响的行数： "+row);
    }

    @Override
    public void updateInfo(ClassesSubjectTb classesSubjectInfo) {
        int row = classesSubjectTbMapper.updateByPrimaryKeySelective(classesSubjectInfo);
        System.out.println("ClassesSubject更新数据影响的行数： "+row);
    }

    @Override
    public Result queryById(Integer classesSubjectId) {
        ClassesSubjectTb classesSubjectInfo = classesSubjectTbMapper.selectByPrimaryKey(Long.valueOf(classesSubjectId));

        System.out.println("ClassesSubject查询的数据为： "+classesSubjectInfo);

        return ResultBuild.buildOk(new Result<ClassesSubjectTb>(),classesSubjectInfo);
    }

    @Override
    public ResultPage<ClassesSubjectTb> queryList(ClassesSubjectPageVo classesSubjectPageVo) {
        int counts=0;
        //总页数
        Integer page = classesSubjectPageVo.getPage();
        Integer pageSize = classesSubjectPageVo.getPageSize();
        int start = PageUtil.getStart(page, pageSize);

        //数据复制
        ClassesSubjectTb classesSubjectTb = new ClassesSubjectTb();
        BeanUtils.copyProperties(classesSubjectPageVo, classesSubjectTb);

        //查询数据
        List<ClassesSubjectTb> classesSubjectTbs =classesSubjectTbMapper.queryList(start,pageSize,classesSubjectTb);


        //查询所有的数据
        counts= classesSubjectTbMapper.queryInfoCount(classesSubjectTb);



        return ResultPageBuild.pageBuildOk(new ResultPage<ClassesSubjectTb>(),page,pageSize,counts,classesSubjectTbs);
    }

    @Override
    public ResultPage<ClassesSubjectTb> querySubjectInfoListByClassesId(ClassesSubjectPageVo classesSubjectPageVo) {
        ClassesSubjectTb classesSubjectTb = new ClassesSubjectTb();
        BeanUtils.copyProperties(classesSubjectPageVo,classesSubjectTb);
        Integer pageSize = classesSubjectPageVo.getPageSize();

        System.out.println("classesSubjectPageVo = " + classesSubjectPageVo);
        //计算总数
        int start = PageUtil.getStart(classesSubjectPageVo.getPage(), classesSubjectPageVo.getPageSize());

        List<ClassesSubjectTb> classesSubjectTbs = classesSubjectTbMapper.querySubjectInfoListByClassesId(classesSubjectTb,start,pageSize);
        //计算总数


        int counts = classesSubjectTbMapper.queryInfoCount(classesSubjectTb);
        return ResultPageBuild.pageBuildOk(new ResultPage<ClassesSubjectTb>(),classesSubjectPageVo.getPage(),classesSubjectPageVo.getPageSize(),counts,classesSubjectTbs);
    }

    @Override
    public ResultPage<ClassesSubjectTb> queryClassesSubjectInfoByTeacherSubjectId(List<Integer> teacherSubjectIdList) {
        List<ClassesSubjectTb> classesSubjectTbs = classesSubjectTbMapper.queryClassesSubjectInfoByTeacherSubjectId(teacherSubjectIdList);
        ResultPage<ClassesSubjectTb> classesSubjectTbResultPage = new ResultPage<>();
        classesSubjectTbResultPage.setData(classesSubjectTbs);

        return classesSubjectTbResultPage;
    }
}
